import { Observable, Subject } from "rxjs";
import { PopOption, Base } from "../model/base";
import { SFSchema } from "../sf/interface";
import { NzSafeAny, SFInstance } from "../sf/type";
import { ITreeTableOption, STExposeComponent } from "../st/interface";

export interface ICurdOption<
  T = Record<string, NzSafeAny>,
  O = Record<string, NzSafeAny>
> extends ITreeTableOption<T> {
  search?: SFSchema<T>;
  searchSpan?: number;
  model?: "dialog" | "drawer";
  option?: PopOption<O>;
  record?: TRecord;
  stModa?: "tree-table" | "table" | "edit-table";
  noCache?: boolean;
  expandParams?: Record<string, NzSafeAny>;
}

export type TCrudComponent = {
  st: STExposeComponent;
  sf: SFInstance;
  update: (data: Record<string, NzSafeAny>) => Observable<unknown>;
  delOne: (id: string) => Observable<unknown>;
  add: (
    data?: Record<string, NzSafeAny>,
    title?: string,
    model?: string
  ) => Observable<unknown>;
};

export type TRecord<T = Record<string, any>> = {
  schema: SFSchema;
  format?: (data: T) => T;
  url?: string;
};

export type TCrudModel<T = Base<any>> = {
  helper?: T;
  openSub?: Subject<null>;
  record: TRecord;
  i: Record<string, NzSafeAny>;
};
